package com.futvan.z.system.zreport;

import com.futvan.z.framework.common.bean.Result;
import com.futvan.z.framework.core.SuperAction;
import com.futvan.z.framework.core.z;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
@Controller
public class ZreportAction extends SuperAction{
	@Autowired
	private ZreportService zreportService;


	/**
	 * 为报表创建编辑类按钮
	 * 该功能主要用于编辑其它数据库数据
	 * @param bean
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="/ReportCreateEditButton")
	public @ResponseBody Result ReportCreateEditButton(@RequestParam HashMap<String,String> bean) throws Exception {
		Result result = new Result();
		String zid = bean.get("zid");
		z_report r = sqlSession.selectOne("z_report_select_zid",zid);
		String [] tablearray = r.getTableid().split(",");
		if(z.isNotNull(r) && tablearray.length==1){
			//生成编辑按钮
			zreportService.CreateReportEditButton(zid);
			result.setSuccess();
		}else{
			result.setError("报表非单表，无法编辑数据");
		}
		return result;
	}

	/**
	 * 插入
	 * @param bean
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="/ZreportInsert")
	public @ResponseBody Result ZreportInsert(@RequestParam HashMap<String,String> bean) throws Exception {
		GetSessionInfoToBean(bean, request);
		Result result = zreportService.insertData(bean,request);
		if(result.ifSuccess()){
			//更新缓存
			RLoadParameter();
		}
		return result;
	}

	/**
	 * 修改
	 * @param bean
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="/ZreportUpdate")
	public @ResponseBody Result ZreportUpdate(@RequestParam HashMap<String,String> bean) throws Exception {
		GetSessionInfoToBean(bean, request);
		return zreportService.updateData(bean,request);
	}
}
